
/**
  题目:
     给定一棵二叉树，想象自己站在它的右侧，按照从顶部到底部的顺序，返回从右侧所能看到的节点值。

     示例:
     
     输入: [1,2,3,null,5,null,4]
     输出: [1, 3, 4]
     解释:
     
        1            <---
      /   \
     2     3         <---
      \     \
       5     4       <---
     
 
     
 
 
   思路:
      1. 队列
	  2. 递归
	 
*/
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    vector<int> rightSideView(TreeNode* root) {
        if(!root){
            return {};
        }
        queue<TreeNode*> path;
        vector<int> res;
        path.push(root);
        while(!path.empty()){
            int size=path.size();
            for(int i=0;i<size;i++){
                TreeNode*node=path.front();
                if(i==size-1){
                    
                    res.push_back(node->val);
                }
                 path.pop();
                if(node->left) path.push(node->left);
                if(node->right) path.push(node->right);
            }
        }
        return res;
    }
};



/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
vector<int> res;
    vector<int> rightSideView(TreeNode* root) {
        if(!root){
            return {};
        }
         rightSideView( root,0);
        return res;
    }
    void rightSideView(TreeNode* root,int level){
        if(!root){
            return ;
        }
        if(level==res.size()){
            res.push_back(root->val);
        }
        //换一下就是左子树视图了
        rightSideView( root->right,  level+1);
        rightSideView( root->left,  level+1);
        return ;
    }

};